Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update beamloading #906

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open

Update beamloading #906

wants to merge 8 commits into from

Conversation

lcarver
Copy link
Contributor

@lcarver lcarver commented Mar 6, 2025

Added the ability to specify an additional detuning angle in the beam loading element. When considering stability issues for active cavities, it can be desirable to apply a delta detuning angle from the optimum working point.

By specifying 'detune_angle' the feedback loop will feedback on the phase position of the optimum + detune_angle.

Below is a plot comparing the PyAT results with results based on the analytical formula (taken from MB2). There is some small disagreement, but the analytical formula contains a large amount of assumptions, whereas the numerical tracking of PyAT has fewer assumptions and also takes into account the bunch distribution

unnamed

I also show here a plot showing that the detune_angle is implemented correctly, as the beam remains centered on 0 as a function of the detune_angle.

unnamed

@lfarv
Copy link
Contributor

lfarv commented Mar 6, 2025

@lcarver
You are experiencing a known bug in atmexall which hides the compilation errors. This has been corrected in the "crab_cavity" branch, but it's still far from being merged…
The easiest way would be to correct it here, it's such an obvious modification. Or open another PR just for that, which I would immediately approve

@lcarver
Copy link
Contributor Author

lcarver commented Mar 6, 2025

Hello Laurent,
I have pushed the fix here. I found the bug but was trying to merge it separately. But if you think it's ok to mix the two together. I open this PR for review, which includes the beamloading update and the bugfix for atmexall

@lcarver lcarver requested review from lfarv and swhite2401 and removed request for lfarv March 6, 2025 11:34
@@ -103,7 +105,7 @@ void BeamLoadingCavityPass(double *r_in,int num_particles,int nbunch,
psi = vgenk[1];
}
/*Track RF cavity is always done. */
trackRFCavity(r_in,le,vgen/energy,rffreq,harmn,tlag,-psi,nturn,circumference/C0,num_particles);
trackRFCavity(r_in,le,vgen/energy,rffreq,harmn,tlag,-psi+detune_angle,nturn,circumference/C0,num_particles);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't you want detune_angle to have the same sign as psi?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. The Vgen[1] is psi, and for a main cavity in electron machines the optimum is at -ve psi, which is -ve detuning in frequency due to the -ve gradient. It is the opposite for harmonic cavities.

I prefer to keep it as an absolute delta, which is the most logical.

@@ -154,6 +154,8 @@ def __init__(self, family_name: str, length: float, voltage: float,
cavitymode (CavityMode): Is cavity ACTIVE (default) or PASSIVE
buffersize (int): Size of the history buffer for vbeam, vgen, vbunch
(default 0)
detune_angle: Fixed detuning from optimal tuning angle. [rad]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should you describe the sign convention here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may want to add this in the docstring of add_beamloading function as well no?

@@ -149,7 +149,7 @@ function atmexall(varargin)
compile(compargs, pmeth);
catch errcomp
if fail
rethrow(err);
rethrow(errcomp);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this to be fixed in another PR then? Maybe you should start with this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants